package com.dqp.cslggroup;


import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.WallpaperInfo;
import android.app.WallpaperManager;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.MediaStore;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.cardview.widget.CardView;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.viewpager.widget.ViewPager;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.dqp.cslggroup.Api.appApi;
import com.dqp.cslggroup.Api.schoolApi;
import com.dqp.cslggroup.Api.xxmhApi;
import com.dqp.cslggroup.EventBus.MessageEvent;
import com.dqp.cslggroup.Features.Setting;
import com.dqp.cslggroup.Features.market;
import com.dqp.cslggroup.JWXT.JWXT_main;
import com.dqp.cslggroup.School.DormitoryIP;
import com.dqp.cslggroup.School.login_daka;
import com.dqp.cslggroup.School.shareCourse;
import com.dqp.cslggroup.SubjectView.AddCourse;
import com.dqp.cslggroup.SubjectView.SubjectViewPagerAdapter;
import com.dqp.cslggroup.UI.*;
import com.dqp.cslggroup.Util.*;
import com.dqp.cslggroup.Web.myWeb;
import com.dqp.cslggroup.about.about;
import com.dqp.cslggroup.bean.Calendar;
import com.dqp.cslggroup.bean.*;
import com.dqp.cslggroup.greendao.courseDao;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import pub.devrel.easypermissions.AppSettingsDialog;
import pub.devrel.easypermissions.EasyPermissions;

import java.io.ByteArrayInputStream;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


public class MainActivity extends BaseActivity implements EasyPermissions.PermissionCallbacks {
    @SuppressLint("StaticFieldLeak")
    public int flag;
    private String xh_text;
    private int zhou = TimeTools.course_zhoushu(MyApplication.getContext());
    private FloatingActionButton floatingActionButton;
    private ViewPager viewPager;
    private BottomSheetBehavior bottomSheetBehavior;
    private String sno;
    private TextView daka, daka_title, eb, eb_title, room, ip, consummer;
    private TextView consummer_title, book, book_title, title, msg;
    private String couplesBg = null;
    private ImageView course_img;
    private CardView cardView;
    static String[] permissions = {
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_CALENDAR,
            Manifest.permission.WRITE_CALENDAR,
            Manifest.permission.READ_EXTERNAL_STORAGE
    };
    private boolean couples = true;
    private TextView tv;
    private Map<String, String> cookies = new HashMap<>();
    private List<Consumer> consumerList = new ArrayList<>();
    private List<Borrow> borrowList = new ArrayList<>();
    ExecutorService threadPool = Executors.newFixedThreadPool(5);

    //fkx12830naek79nfkia8p7b
    @Override
    @SuppressLint("ClickableViewAccessibility")
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.app_bar_main);
        EventBus.getDefault().register(this);
        sno = SharedPreferencesUtil.getStringSp(this, "stuNum", null);
        onInit();
    }

    protected void onInit() {
        initToolbar();
        setWallpaper();
        initAvatarName();
        viewPagerView();
        intiWeekValue();
        kao();
        bottonMenu();
        coupleSchedule();
        getCalendar();
        if (NetCheckUtil.checkNet(this)) {
            Handler handler = new Handler();
            handler.postDelayed(() -> {
                String ip = SharedPreferencesUtil.getIp(this);
                if (!StringUtil.isEmpty(ip, 5)) {
                    getPush();
                    getElectricityBill();
                    getIp();
                    update();
                    getConsummer();
                    book();
                    daka();
                } else ToastUtil.showToast("🔗服务器未连接");
            }, 1000);
//            illegalSign();
        }
    }

    public void initToolbar() {
        Toolbar toolbar = findViewById(R.id.toolbar);
        toolbar.setTitle("");
        setSupportActionBar(toolbar);
        TextView addcourse = findViewById(R.id.iv_add_coure);
        TextView shuaxing = findViewById(R.id.iv_shuxing);
        TextView clear = findViewById(R.id.iv_clear_coure);
        tv = findViewById(R.id.activity_course_zhoushu);
        cardView = findViewById(R.id.push_CardView);
        title = findViewById(R.id.push_title);
        msg = findViewById(R.id.push);
        msg.setMovementMethod(ScrollingMovementMethod.getInstance());
        clear.setOnClickListener(v3 -> ToastUtil.showToast("✔长按清空所有课程数据"));
        clear.setOnLongClickListener(v -> {
            MyApplication.getDaoInstant().getCourseDao().deleteAll();
            EventBus.getDefault().post(new MessageEvent("SubjectFragment", true));
            return true;
        });
        addcourse.setOnClickListener(v2 -> UiUtils.startActivityForResult(this, AddCourse.class, 1));
        shuaxing.setOnClickListener(v1 -> {
            if (couples) EventBus.getDefault().post(new MessageEvent("SubjectFragment", true));
            else EventBus.getDefault().post(new MessageEvent("SubjectFragment", 1));
            ToastUtil.showToast("✌刷新完成");
        });
        int show = SharedPreferencesUtil.getIntSp(this, "pushDisShow", -2);
        if (show == -2) cardView.setVisibility(View.VISIBLE);
        cardView.setOnLongClickListener(v3 -> {
            cardView.setVisibility(View.GONE);
            int id = SharedPreferencesUtil.getIntSp(this, "push_id", -1);
            SharedPreferencesUtil.putIntSp(this, "pushDisShow", id);
            return true;
        });
    }

    @SuppressLint("CutPasteId")
    public void bottonMenu() {
        View design_bottom_sheet = findViewById(R.id.design_bottom_sheet);
        bottomSheetBehavior = BottomSheetBehavior.from(design_bottom_sheet);
        bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
        TextView menu = findViewById(R.id.menu_more);
        menu.setOnClickListener(v -> {
            setVerse();
            GridView gridView = findViewById(R.id.menu_grid);
            menuAdapter menuAdapter = new menuAdapter(this);
            gridView.setOnItemClickListener((parent, view, position, id) -> {
                switch (position) {
                    case 0:
                        UiUtils.startActivity(this, JWXT_main.class);
//                        String jwxt = SharedPreferencesUtil.getStringSp(this, "password_JWXT", null);
//                        if (StringUtil.isEmpty(jwxt, 6)) {
//                            AlertDialog alertDialog = new AlertDialog(this);
//                            alertDialog.builder();
//                            alertDialog.setGone()
//                                    .setTitle("账号绑定异常")
//                                    .setMsg("检测到您还没有绑定教务系统账号，请前往完成绑定！")
//                                    .setMsgGravity(false)
//                                    .setNegativeButton("前往", R.color.colorAccent, v1 -> {
//                                        alertDialog.dismiss();
//                                        UiUtils.startActivity(this, newStudent.class);
//                                    })
//                                    .setPositiveButton("取消", R.color.colorAccent, v2 -> {
//                                        alertDialog.dismiss();
//                                    })
//                                    .show();
//                        } else UiUtils.startActivity(this, JWXT_main.class);
                        break;
                    case 1:
                        AlertDialog alertDialog = new AlertDialog(this);
                        alertDialog.builder();
                        alertDialog.setGone()
                                .setTitle("🗓cal日历课程")
                                .setMsg("ical日历课程可将课程信息生成相应的ics文件就📝，该文件支持电脑💻、安卓📱、iPhone📲使用，无需第三方应用支持！\n" +
                                        "💖欢迎推荐给身边的iPhone用户👩")
                                .setMsgGravity(false)
                                .setNegativeButton("前往🔗", R.color.colorAccent, v1 -> {
                                    alertDialog.dismiss();
                                    Intent intent = new Intent(this, myWeb.class);
                                    intent.putExtra("url", "https://www.cslggroup.top/ical/");
                                    startActivity(intent);
                                })
                                .setPositiveButton("分享👩", R.color.colorAccent, v2 -> {
                                    ClipboardManager cm = (ClipboardManager) this.getSystemService(Context.CLIPBOARD_SERVICE);
                                    ClipData mClipData = ClipData.newPlainText("Label", "📅ical日历课程🎉\n" +
                                            "将课程信息直接写入日历📅，无需第三方应用支持📵，生成上课日程提醒🔔，支持Android、iPhone、PC功能获取地址（🔗复制链接在浏览器打开）：\n" +
                                            "https://www.cslggroup.top/ical/\nhttps://dqp2375.gitee.io/imk/ical/\n");
                                    if (cm != null) {
                                        cm.setPrimaryClip(mClipData);
                                        alertDialog.dismiss();
                                        ToastUtil.showToast("✌复制成功，快去粘贴发送给小伙伴吧🎉");
                                    } else ToastUtil.showToast("分享失败");
                                })
                                .show();

                        break;
                    case 2:
//                        UiUtils.startActivity(this, XSGZ_login.class);
                        ToastUtil.showToast("😁暂不可用");
                        break;
                    case 3:
                        UiUtils.startActivity(this, Setting.class);
                        break;
                    case 4:
                        UiUtils.startActivity(this, about.class);
                        break;
                }
            });
            gridView.setAdapter(menuAdapter);
            if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN) {
                bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
            } else if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
                bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
            }
//            menuViewPage();
        });
    }

    private void getElectricityBill() {
        eb = findViewById(R.id.e_msg);
        eb_title = findViewById(R.id.e_title);
        room = findViewById(R.id.room_msg);
        String ss = SharedPreferencesUtil.getStringSp(this, "room", null);
        String don = SharedPreferencesUtil.getStringSp(this, "donS", null);
        String ssh = SharedPreferencesUtil.getStringSp(this, "sshS", null);
        String xq = SharedPreferencesUtil.getStringSp(this, "xq", null);
        String bedid = SharedPreferencesUtil.getStringSp(this, "bedid", null);
        if (ss != null && ssh != null && don != null && xq != null && bedid != null) room.setText(ss);
        else room.setText("未绑定");
        String roomElectricity = SharedPreferencesUtil.getStringSp(this, "roomElectricity", null);
        String roomElectricityTime = SharedPreferencesUtil.getStringSp(this, "roomElectricityTime", null);
        if (!StringUtil.isEmpty(roomElectricity) && !StringUtil.isEmpty(roomElectricityTime)) {
            eb.setText(roomElectricity);
            eb_title.setText(roomElectricityTime + "剩余电量");
        }
        room.setOnClickListener(v1 -> DialogView.roomElectricity(this, room));
        eb.setOnClickListener(v -> {
            String sss = SharedPreferencesUtil.getStringSp(this, "room", null);
            String dons = SharedPreferencesUtil.getStringSp(this, "donS", null);
            String sshs = SharedPreferencesUtil.getStringSp(this, "sshS", null);
            String xqs = SharedPreferencesUtil.getStringSp(this, "xq", null);
            if (sss != null && sshs != null && dons != null && xqs != null) {
                EventBus.getDefault().post(new MessageEvent("MainActivity", 11, "查询中…"));
                getElectricity(xqs, dons, sshs);
            } else DialogView.roomElectricity(MainActivity.this, room);
        });
        eb.setOnLongClickListener(v2 -> {
            List<roomElectricity> roomElectricities = MyApplication.getDaoInstant().getRoomElectricityDao().loadAll();
            DialogView.moreEBill(this, "电量记录", roomElectricities);
            return true;
        });
    }

    private void getElectricity(String xq, String don, String ssh) {
        if (StringUtil.isEmpty(xq, don, ssh)) return;
        threadPool.execute(() -> {
            electricity electricity = schoolApi.getElectricity(xq, don, ssh);
            if (electricity == null) return;
            if (electricity.getReturncode() != null && electricity.getReturncode().equals("100") && electricity.getQuantity() != null) {
                SharedPreferencesUtil.putStringSp(MainActivity.this, "roomElectricity", electricity.getQuantity() + electricity.getQuantityunit());
                SharedPreferencesUtil.putStringSp(MainActivity.this, "roomElectricityTime", GetTimeUtil.getNowDate());
                roomElectricity roomElectricity = new roomElectricity();
                roomElectricity.setQuantity(electricity.getQuantity());
                roomElectricity.setTime(GetTimeUtil.getNowDate());
                roomElectricity.setRoom(don + "-" + ssh);
                MyApplication.getDaoInstant().getRoomElectricityDao().insertOrReplace(roomElectricity);
                EventBus.getDefault().post(new MessageEvent("MainActivity", 11, GetTimeUtil.getNowDate() + "剩余电量", electricity.getQuantity() + electricity.getQuantityunit()));
            } else if (electricity.getReturncode() != null && electricity.getReturncode().equals("FAIL")) {
                EventBus.getDefault().post(new MessageEvent("MainActivity", 11, "剩余电量", "宿舍信息错误！请重新设置！"));
            } else
                EventBus.getDefault().post(new MessageEvent("MainActivity", 11, "剩余电量", "查询失败！请检查网络后重试！"));
        });
    }

    private void getIp() {
        ip = findViewById(R.id.ip_msg);
        String ips = SharedPreferencesUtil.getStringSp(this, "roomip", null);
        if (!StringUtil.isEmpty(ips)) ip.setText(ips);
        else {
            String don = SharedPreferencesUtil.getStringSp(this, "donS", null);
            String ssh = SharedPreferencesUtil.getStringSp(this, "sshS", null);
            String xq = SharedPreferencesUtil.getStringSp(this, "xq", null);
            String bedid = SharedPreferencesUtil.getStringSp(this, "bedid", null);
            if (!StringUtil.isEmpty(don, ssh, xq, bedid))
                roomIp(don, ssh, xq, bedid);
        }
        ip.setOnClickListener(v -> {
            String don = SharedPreferencesUtil.getStringSp(this, "donS", null);
            String ssh = SharedPreferencesUtil.getStringSp(this, "sshS", null);
            String xq = SharedPreferencesUtil.getStringSp(this, "xq", null);
            String bedid = SharedPreferencesUtil.getStringSp(this, "bedid", null);
            if (!StringUtil.isEmpty(don, ssh, xq, bedid))
                roomIp(don, ssh, xq, bedid);
            else DialogView.roomElectricity(MainActivity.this, room);
        });
        ip.setOnLongClickListener(v2 -> {
            UiUtils.startActivity(this, DormitoryIP.class);
            return true;
        });
    }

    public void roomIp(String don, String ssh, String xq, String bedid) {
        if (StringUtil.isEmpty(don, ssh, xq, bedid)) return;
        threadPool.execute(() -> {
            EventBus.getDefault().post(new MessageEvent("MainActivity", 13, "查询中..."));
            int campus = Integer.parseInt(xq);
            if (campus == 1) campus = 2;
            if (campus == 3) campus = 1;
            JSONObject jsonObject = schoolApi.getIp(campus + "", don, ssh, bedid);
            if (jsonObject != null && Result.jsonResultIsTure(jsonObject)) {
                JSONObject result = jsonObject.getJSONObject("ip");
                ip ip = result.toJavaObject(ip.class);
                SharedPreferencesUtil.putStringSp(this, "roomip", ip.getIp().replace("IP地址: ", ""));
                EventBus.getDefault().post(new MessageEvent("MainActivity", 13, ip.getIp().replace("IP地址: ", "")));
            } else {
                EventBus.getDefault().post(new MessageEvent("MainActivity", 13, jsonObject.getString("resultMsg")));
            }
        });
    }

    private void getConsummer() {
        consummer = findViewById(R.id.consumption_msg);
        consummer_title = findViewById(R.id.consumption_title);
        String sno = SharedPreferencesUtil.getStringSp(this, "stuNum", null);
        String xf = SharedPreferencesUtil.getStringSp(this, "consumption", null);
        String month = SharedPreferencesUtil.getStringSp(this, "consumptionMonth", null);
        if (StringUtil.isEmpty(sno))
            EventBus.getDefault().post(new MessageEvent("MainActivity", 14, "未绑定"));
        if (!StringUtil.isEmpty(xf)) consummer.setText(xf);
        if (!StringUtil.isEmpty(month)) consummer_title.setText(month);
        consummer.setOnClickListener(v -> {
            String xh = SharedPreferencesUtil.getStringSp(this, "stuNum", null);
            if (!StringUtil.isEmpty(xh))
                consumption(xh, 1, 1);
            else EventBus.getDefault().post(new MessageEvent("MainActivity", 14, "未绑定"));
        });
        consummer.setOnLongClickListener(v1 -> {
            EventBus.getDefault().post(new MessageEvent("MainActivity", 18, "未绑定"));
            return true;
        });
    }

    public void consumption(String sno, int currentPage, int pageNumber) {
        if (StringUtil.isEmpty(sno)) return;
        threadPool.execute(() -> {
            EventBus.getDefault().post(new MessageEvent("MainActivity", 14, "查询中..."));
            JSONObject jsonObject = xxmhApi.getConsumerList(sno, currentPage, pageNumber, cookies);
            if (Result.jsonResultIsTure(jsonObject)) {
                if (jsonObject.containsKey("data")) {
                    jsonObject = jsonObject.getJSONObject("data");
                    if (jsonObject.containsKey("items")) {
                        String str = jsonObject.getString("items");
                        JSONArray array = JSONObject.parseArray(str);
                        if (array != null) {
                            for (Object o : array) {
                                JSONObject js = (JSONObject) o;
                                Consumer consumer = js.toJavaObject(Consumer.class);
                                consumerList.add(consumer);
                            }
                            Consumer consumer = consumerList.get(0);
                            SharedPreferencesUtil.putStringSp(this, "consumption", (consumer.getCyxf() + consumer.getQtxf() + consumer.getScgw()) + "元");
                            SharedPreferencesUtil.putStringSp(this, "consumptionMonth", consumer.getTjyf() + "校园卡消费");
                            EventBus.getDefault().post(new MessageEvent("MainActivity", 14, consumer.getTjyf() + "校园卡消费", (consumer.getCyxf() + consumer.getQtxf() + consumer.getScgw()) + "元"));
                        }
                    } else {
                        EventBus.getDefault().post(new MessageEvent("MainActivity", 14, jsonObject.getString("resultMsg")));
                    }
                }
            }
        });
    }

    public void book() {
        book = findViewById(R.id.book_msg);
        book_title = findViewById(R.id.book_title);
        String num = SharedPreferencesUtil.getStringSp(this, "bookNum", null);
        String stutas = SharedPreferencesUtil.getStringSp(this, "bookStatus", null);
        if (!StringUtil.isEmpty(num, stutas)) {
            if (stutas.equals("超期图书")) book.setTextColor(getColor(R.color.mb_red));
            if (stutas.equals("即将到期")) book.setTextColor(getColor(R.color.yellow));
            book.setText(num);
            book_title.setText(stutas);
        }
        book.setOnClickListener(v -> {
            String xh = SharedPreferencesUtil.getStringSp(this, "stuNum", null);
            if (!StringUtil.isEmpty(xh)) {
                getCookies();
                getBook(xh);
            } else EventBus.getDefault().post(new MessageEvent("MainActivity", 15, "🤦‍"));
        });
        book.setOnLongClickListener(v2 -> {
            String xh = SharedPreferencesUtil.getStringSp(this, "stuNum", null);
            if (!StringUtil.isEmpty(xh)) {
                getCookies();
                getBorrowBook(xh);
            }
            return true;
        });
    }

    public void getBook(String sno) {
        if (StringUtil.isEmpty(sno)) return;
        threadPool.execute(() -> {
            EventBus.getDefault().post(new MessageEvent("MainActivity", 17, "查询中..."));
            JSONObject jsonObject = xxmhApi.getBook(sno, cookies);
            if (Result.jsonResultIsTure(jsonObject)) {
                if (jsonObject.containsKey("data")) {
                    JSONArray array = jsonObject.getJSONArray("data");
                    List<BookBorrow> bookBorrows = new ArrayList<>();
                    for (Object o : array) {
                        JSONObject jsonObject1 = (JSONObject) o;
                        BookBorrow bookBorrow = jsonObject1.toJavaObject(BookBorrow.class);
                        bookBorrows.add(bookBorrow);
                    }
                    if (bookBorrows != null && bookBorrows.size() > 0) {
                        BookBorrow bookBorrow = bookBorrows.get(0);
                        EventBus.getDefault().post(new MessageEvent("MainActivity", 16, bookBorrow));
                    } else {
                        SharedPreferencesUtil.putStringSp(this, "bookNum", "0本");
                        SharedPreferencesUtil.putStringSp(this, "bookStatus", "图书借阅");
                        EventBus.getDefault().post(new MessageEvent("MainActivity", 17, "0本"));
                    }
                }
            } else EventBus.getDefault().post(new MessageEvent("MainActivity", 17, "❓"));
        });
    }

    public void getBorrowBook(String sno) {
        if (StringUtil.isEmpty(sno)) return;
        threadPool.execute(() -> {
            JSONObject jsonObject = xxmhApi.getBookDetail(sno, 1, 5, cookies);
            if (Result.jsonResultIsTure(jsonObject)) {
                if (jsonObject.containsKey("data")) {
                    jsonObject = jsonObject.getJSONObject("data");
                    if (jsonObject.containsKey("items")) {
                        JSONArray array = jsonObject.getJSONArray("items");
                        for (Object o : array) {
                            JSONObject jsonObject1 = (JSONObject) o;
                            Borrow bookBorrow = jsonObject1.toJavaObject(Borrow.class);
                            borrowList.add(bookBorrow);
                        }
                        if (borrowList != null && borrowList.size() > 0) {
                            EventBus.getDefault().post(new MessageEvent("MainActivity", 19, borrowList));
                        }
                    }
                }
            }
        });
    }

    public void getCalendar() {
        TextView schccool_year = findViewById(R.id.school_year);
        TextView vacation = findViewById(R.id.vacation);
        Calendar calendar = new Calendar();
        List<Calendar> calendars = MyApplication.getDaoInstant().getCalendarDao().loadAll();
        if (calendars != null && calendars.size() > 0)
            calendar = calendars.get(0);
        schccool_year.setText(calendar.getSchoolYear() + "学年第" + calendar.getSemester() + "学期");
        vacation.setText("距离暑假还有：" + calendar.getHoliday() + "天");
    }


    public void getCookies() {
        Map<String, String> map = SharedPreferencesUtil.getMap(this, "cookies");
        long time = SharedPreferencesUtil.getLongSp(this, "cookiesTime", 0);
        long nowTime = GetTimeUtil.getCurrentTimeMillis();
        long x = GetTimeUtil.minuteDifference(nowTime, time);
        if (x < 10) cookies = map;
        else {
            String xxmh = SharedPreferencesUtil.getStringSp(this, "password_XXMH", null);
            String sno = SharedPreferencesUtil.getStringSp(this, "stuNum", null);
            if (!StringUtil.isEmpty(xxmh, sno)) {
                threadPool.execute(() -> {
                    JSONObject jsonObject = xxmhApi.login(sno, xxmh, "0");
                    if (Result.jsonResultIsTure(jsonObject)) {
                        JSONObject object = jsonObject.getJSONObject("info");
                        cookies = JSONObject.parseObject(object.toJSONString(), new TypeReference<Map<String, String>>() {
                        });
                        CookiesUtil.save(this, cookies);
                    } else if (jsonObject.containsKey("resultMsg") && jsonObject.getJSONObject("resultMsg").containsKey("密码错误")) {
                        alertDialog("密码错误", "您绑定的信息门户账号密码错误，您近期是否进行了密码更改？" +
                                "现已无法正常使用该模块功能，为确保正常使用请前往设置重新绑定！");
                    }
                });
            } else {
                alertDialog("账号未绑定", "检测到您绑定的信息门户、教务系统账号或密码信息缺失，无法正常使用该模块功能，" +
                        "为确保正常使用请前往设置进行绑定！");
            }
        }
    }

    public void alertDialog(String title, String msg) {
        if (StringUtil.isEmpty(title, msg)) return;
        AlertDialog alertDialog = new AlertDialog(this);
        alertDialog.builder();
        alertDialog.setGone()
                .setTitle(title)
                .setMsg(msg)
                .setMsgGravity(false)
                .setNegativeButton("设置", R.color.colorAccent, v1 -> {
                    alertDialog.dismiss();
                    UiUtils.startActivity(this, Setting.class);
                })
                .setPositiveButton("取消", R.color.colorAccent, v2 -> {
                    alertDialog.dismiss();
                    finish();
                })
                .show();
    }

//    private void menuViewPage() {
//        ViewPager viewPager = findViewById(R.id.button_menu_viewpage);
//        NoteViewAdapter noteViewAdapter = new NoteViewAdapter(getSupportFragmentManager(), 0);
//        viewPager.setAdapter(noteViewAdapter);
//        viewPager.setCurrentItem(1);
//        viewPager.setOffscreenPageLimit(0);
//        UiUtils.addLayoutListener(design_bottom_sheet, viewPager);
//
//    }

    private void setVerse() {
        TextView verse = findViewById(R.id.verse);
        verse.setText(getVerse());
        verse.setOnClickListener(v -> verse.setText(getVerse()));
    }

    private String getVerse() {
        int random = new Random().nextInt(5);
        String msg;
        switch (random) {
            case 0:
                msg = "曾经沧海难为水，除却巫山不是云";
                break;
            case 1:
                msg = "浮云一别后，流水十年间";
                break;
            case 2:
                msg = "吹灭读书灯，一身都是月";
                break;
            case 3:
                msg = "人生如逆旅，我亦是行人";
                break;
            case 4:
                msg = "流光容易把人抛，红了樱桃，绿了芭蕉";
                break;
            default:
                msg = "人生到处知何似，应似飞鸿踏雪泥";
        }
        return msg;
    }

    public void viewPagerView() {
        viewPager = findViewById(R.id.timeTable_view_pager);
        SubjectViewPagerAdapter adapter = new SubjectViewPagerAdapter(getSupportFragmentManager(), zhou);
        viewPager.setAdapter(adapter);
        if (zhou > 20) zhou = 0;
        viewPager.setCurrentItem(zhou);
        viewPager.setOffscreenPageLimit(0);
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {
            }

            @Override
            public void onPageSelected(int i) {
                int x = zhou;
                zhou = viewPager.getCurrentItem();
                intiWeekValue();
                EventBus.getDefault().post(new MessageEvent("SubjectFragmentLazyLoad", 66));
            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });
    }

    public int toValue() {
        return viewPager.getCurrentItem();
    }

    public boolean toCouples() {
        return couples;
    }

    public void illegalSign() {
        SignCheck signCheck = new SignCheck(this);
        String SHA1 = "77:2B:FE:62:69:DA:1D:36:6B:2B:3D:DD:F0:4E:0A:DE:44:F8:E6:CF";
        signCheck.setRealCer(SHA1);
        if (!signCheck.check()) {
            final com.dqp.cslggroup.UI.AlertDialog alertDialog = new com.dqp.cslggroup.UI.AlertDialog(MainActivity.this);
            alertDialog.builder();
            alertDialog.setGone()
                    .setTitle("非法签名")
                    .setMsg("检测到您使用的安装包进行了非法签名，" +
                            "存在严重的安全威胁，" +
                            "请立即卸载该安装包！" +
                            "请在我们的官网或正规应用市场下载！")
                    .setNegativeButton("应用市场", R.color.colorAccent, v -> market.startMarket(MainActivity.this))
                    .setPositiveButton("酷安下载", R.color.colorAccent, v -> {
                        Uri uri = Uri.parse("https://www.coolapk.com/apk/246419");
                        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                        startActivity(intent);
                    }).show();
            ToastUtil.showLongToast("5秒后自动关闭应用...");
            Handler handler = new Handler();
            handler.postDelayed(() -> {
                System.exit(0);
                finish();
            }, 10000);
        }
    }

    public void setWallpaper() {
        String path = SharedPreferencesUtil.getStringSp(this, "bg_path", null);
        int blur = SharedPreferencesUtil.getIntSp(this, "blur", 0);
        if (blur >= 25) blur = 24;
        if (blur < 0) blur = 0;
        CoordinatorLayout layout = findViewById(R.id.main_layout);
        if (EasyPermissions.hasPermissions(this, permissions)) {
            if (path != null && CompressedBitmap.fileExist(path)) {
                Bitmap bitmap = BitmapFactory.decodeFile(path);
                if (bitmap != null) {
                    if (blur != 0) bitmap = UiUtils.rsBlur(this, bitmap, blur, 0.5f);
                    Drawable drawable = new BitmapDrawable(getResources(), bitmap);
                    layout.setBackground(drawable);
                } else {
                    SharedPreferencesUtil.removeSp(this, "bg_path");
                    ToastUtil.showToast("背景照片已被移除，已还原背景！");
                }
            } else {
                SharedPreferencesUtil.removeSp(MainActivity.this, "bg_path");
                if (SharedPreferencesUtil.getBooleanSp(this, "showDesktopWallpaper", false)) {
                    Drawable drawable = null;
                    WallpaperManager manager = WallpaperManager.getInstance(this);
                    WallpaperInfo info = manager.getWallpaperInfo();
                    if (info == null) drawable = manager.getDrawable();
                    if (blur != 0 && drawable != null) {
                        Bitmap bitmap = UiUtils.drawableToBitmap(drawable);
                        bitmap = UiUtils.rsBlur(this, bitmap, blur, 0.5f);
                        if (bitmap != null)
                            drawable = new BitmapDrawable(getResources(), bitmap);
                    }
                    if (drawable != null)
                        layout.setBackground(drawable);
                }
            }
        } else {
            EasyPermissions.requestPermissions(this, "请授权以下权限:\n" +
                    "访问日历：设置上课提醒日程\n" +
                    "读写手机存储：自定义背景和头像等功能", 1, permissions);
        }
    }


    @SuppressLint("SetTextI18n")
    public void intiWeekValue() {
        String str;
        if (zhou == 0) {
            str = TimeTools.xinqi();
            tv.setText(str);
        } else tv.setText("第" + viewPager.getCurrentItem() + "周");
    }

    @SuppressLint("SetTextI18n")
    public void coupleSchedule() {
        LinearLayout couples_lin = findViewById(R.id.couples_lin);
        if (!SharedPreferencesUtil.getBooleanSp(MainActivity.this, "showCouples", false))
            couples_lin.setVisibility(View.GONE);
        else {
            String me_name = SharedPreferencesUtil.getStringSp(this, "me_course_name", "我的课表");
            couplesBg = SharedPreferencesUtil.getStringSp(this, "me_course_bg", null);
            View include_couple_1 = findViewById(R.id.include_couple_1);
            RoundImageView me = include_couple_1.findViewById(R.id.iv_pic);
            TextView me_title = include_couple_1.findViewById(R.id.tv_table_name);
            TextView me_del = include_couple_1.findViewById(R.id.ib_delete);
            TextView me_edit = include_couple_1.findViewById(R.id.ib_edit);
            me_title.setText(me_name + "");
            if (couplesBg != null) Glide.with(this).load(couplesBg).into(me);
            me.setOnClickListener(v -> {
                couples = true;
                long count = MyApplication.getDaoInstant().getCourseDao().count();
                if (count == 0)
                    UiUtils.startActivity(this, JWXT_main.class);
                else {
                    intiWeekValue();
                    EventBus.getDefault().post(new MessageEvent("SubjectFragment", 2));
                }
            });
            me_del.setOnClickListener(v -> ToastUtil.showToast("长按删除"));
            me_del.setOnLongClickListener(v -> {
                SharedPreferencesUtil.removeSp(this, "me_course_name");
                SharedPreferencesUtil.removeSp(this, "me_course_bg");
                MyApplication.getDaoInstant().getCourseDao().queryBuilder().where(courseDao.Properties.Who.eq(0)).buildDelete().executeDeleteWithoutDetachingEntities();
                EventBus.getDefault().post(new MessageEvent("MainActivity", 6));
                EventBus.getDefault().post(new MessageEvent("SubjectFragment", 2));
                ToastUtil.showToast("删除成功！");
                return true;
            });
            me_edit.setOnClickListener(v -> DialogView.setCouples(this, me_title.getText().toString(), 0, (save, bg, name, dialog, img) -> {
                bg.setOnClickListener(v1 -> {
                    course_img = img;
                    Intent intent = new Intent(Intent.ACTION_PICK);
                    intent.setType("image/*");
                    startActivityForResult(intent, 1);
                });
                save.setOnClickListener(v1 -> {
                    SharedPreferencesUtil.putStringSp(this, "me_course_name", name.getText().toString());
                    SharedPreferencesUtil.putStringSp(this, "me_course_bg", couplesBg);
                    dialog.dismiss();
                    if (couplesBg != null) Glide.with(this).load(couplesBg).into(me);
                    me_title.setText(name.getText().toString() + "");
                    couplesBg = null;
                });
            }));
            String ta_name = SharedPreferencesUtil.getStringSp(this, "ta_course_name", "Ta的课表");
            couplesBg = SharedPreferencesUtil.getStringSp(this, "ta_course_bg", null);
            View include_couple_2 = findViewById(R.id.include_couple_2);
            TextView ta_title = include_couple_2.findViewById(R.id.tv_table_name);
            RoundImageView ta = include_couple_2.findViewById(R.id.iv_pic);
            TextView ta_del = include_couple_2.findViewById(R.id.ib_delete);
            TextView ta_edit = include_couple_2.findViewById(R.id.ib_edit);
            ta_title.setText(ta_name);
            if (couplesBg != null) Glide.with(this).load(couplesBg).into(ta);
            ta.setOnClickListener(v -> {
                couples = false;
                long count = MyApplication.getDaoInstant().getCourseDao().queryBuilder().where(courseDao.Properties.Who.eq(1)).count();
                if (count == 0)
                    UiUtils.startActivity(this, shareCourse.class);
                else {
                    EventBus.getDefault().post(new MessageEvent("SubjectFragment", 1));
                    intiWeekValue();
                    tv.append("♡" + ta_name);
                }
            });
            ta_del.setOnClickListener(v -> ToastUtil.showToast("长按删除"));
            ta_del.setOnLongClickListener(v -> {
                SharedPreferencesUtil.removeSp(this, "ta_course_name");
                SharedPreferencesUtil.removeSp(this, "ta_course_bg");
                MyApplication.getDaoInstant().getCourseDao().queryBuilder().where(courseDao.Properties.Who.eq(1)).buildDelete().executeDeleteWithoutDetachingEntities();
                EventBus.getDefault().post(new MessageEvent("MainActivity", 6));
                EventBus.getDefault().post(new MessageEvent("SubjectFragment", 2));
                ToastUtil.showToast("删除成功！");
                return true;
            });
            ta_edit.setOnClickListener(v -> DialogView.setCouples(this, ta_title.getText().toString(), 1, (save, bg, name, dialog, img) -> {
                bg.setOnClickListener(v1 -> {
                    course_img = img;
                    Intent intent = new Intent(Intent.ACTION_PICK);
                    intent.setType("image/*");
                    startActivityForResult(intent, 1);

                });
                save.setOnClickListener(v1 -> {
                    SharedPreferencesUtil.putStringSp(this, "ta_course_name", name.getText().toString());
                    SharedPreferencesUtil.putStringSp(this, "ta_course_bg", couplesBg);
                    dialog.dismiss();
                    if (couplesBg != null) Glide.with(this).load(couplesBg).into(ta);
                    ta_title.setText(name.getText().toString() + "");
                    couplesBg = null;
                });
            }));
        }
    }

    @SuppressLint({"SetTextI18n", "SetJavaScriptEnabled"})
    public boolean birthdayWishes(String birthday, String name) {
        if (StringUtil.isEmpty(birthday, name)) return false;
        boolean isbirthday = false;
        @SuppressLint("SimpleDateFormat") SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMdd");
        Date date = new Date(System.currentTimeMillis());
        String b = simpleDateFormat.format(date);
        if (birthday.equals(b) && SharedPreferencesUtil.getBooleanSp(this, GetTimeUtil.getYear() + "", true)) {
            isbirthday = true;
            SharedPreferencesUtil.putBooleanSp(this, GetTimeUtil.getYear() + "", false);
            AlertDialog alertDialog = new AlertDialog(this);
            alertDialog.builder();
            alertDialog.setGone()
                    .setTitle(name + "同学生日快乐！")
                    .setMsg("平安喜乐，得偿所愿。\n" +
                            "愿你一生温暖纯良，不舍爱与自由")
                    .setNegativeButton("朕已阅", R.color.colorAccent, null)
                    .show();
        }
        return isbirthday;

    }


    @SuppressLint("SetTextI18n")
    private void initAvatarName() {
        ImageView head = findViewById(R.id.nav_hade);
        TextView name = findViewById(R.id.nav_name);
        List<student> studentList = MyApplication.getDaoInstant().getStudentDao().loadAll();
        if (studentList.size() > 0) {
//            head.setOnClickListener(v -> UiUtils.startActivity(this, personal_center.class));
            student student = studentList.get(0);
            if (student == null||StringUtil.isEmpty(student.getXm(),student.getZy(),student.getXy()))
                return;
            boolean isbirthday = false;
            String xm_text = student.getXm();
            String zy_text = student.getZy();
            String xy_text = student.getXy();
            if (student.getSr() != null && student.getSr().length() >= 4) {
                String birthday = student.getSr().substring(student.getSr().length() - 4);
                isbirthday = birthdayWishes(birthday, xm_text);
            }
            sno = student.getXh();
            xh_text = student.getXh();
            if (zy_text.length() >= 20) {
                zy_text = zy_text.substring(0, 20) + "...";
            }
            if (xm_text != null) {
                String msg = "";
                if (isbirthday) msg = ",生日快乐！";
                name.setText(xm_text + msg + "\n" + zy_text + "\n" + xy_text);
            }
            List<avatar> avatarList = MyApplication.getDaoInstant().getAvatarDao().loadAll();
            if (avatarList.size() > 0) {
                ByteArrayInputStream stream = new ByteArrayInputStream(avatarList.get(0).getBytes());
                Drawable drawable = Drawable.createFromStream(stream, "img");
                if (drawable != null) {
                    RequestOptions options = new RequestOptions();
                    Glide.with(this).load(drawable).apply(options.circleCrop()).into(head);
                }
            }
//            if (NetCheckUtil.checkNet(MainActivity.this))
//                getDakadata();
        }
    }

    public void daka() {
        daka = findViewById(R.id.daka_msg);
        daka_title = findViewById(R.id.daka_title);
        String count = SharedPreferencesUtil.getStringSp(this, "dakaCount", null);
        String title = SharedPreferencesUtil.getStringSp(this, "dakaTitle", null);
        if (!StringUtil.isEmpty(count, title)) {
            daka.setText(count);
            daka_title.setText(title);
        }
        daka.setOnClickListener(v -> {
            EventBus.getDefault().post(new MessageEvent("MainActivity", 20, "查询中..."));
            sno = SharedPreferencesUtil.getStringSp(this, "stuNum", null);
            getDakaData(sno);
        });
        daka.setOnLongClickListener(v1 -> {
            UiUtils.startActivity(this, login_daka.class);
            return true;
        });
    }

    public void getDakaData(String sno) {
        threadPool.execute(() -> {
            JSONObject jsonObject = schoolApi.getDk(sno);
            if (Result.jsonResultIsTure(jsonObject)) {
                if (jsonObject.containsKey("total") && jsonObject.containsKey("name")) {
                    int count = jsonObject.getIntValue("total");
                    String title = jsonObject.getString("name");
                    SharedPreferencesUtil.putStringSp(this, "dakaCount", count + "次");
                    SharedPreferencesUtil.putStringSp(this, "dakaTitle", title);
                    EventBus.getDefault().post(new MessageEvent("MainActivity", 12, count, title));
                } else EventBus.getDefault().post(new MessageEvent("MainActivity", 12, 0, "未查询到相关数据"));
            } else EventBus.getDefault().post(new MessageEvent("MainActivity", 12, 0, "未查询到相关数据"));

        });
    }


    @SuppressLint("RestrictedApi")
    public void kao() {
        floatingActionButton = findViewById(R.id.fab_kao);
        boolean show_kao = SharedPreferencesUtil.getBooleanSp(this, "show_kao", false);
        if (show_kao) {
            floatingActionButton.setVisibility(View.VISIBLE);
            floatingActionButton.setOnClickListener(v -> initKao());
        }
    }

    @SuppressLint("RestrictedApi")
    public void initKao() {
        boolean x = DialogView.examArrangements(this, floatingActionButton);
        if (!x) {
            SharedPreferencesUtil.removeSp(this, "show_kao");
            floatingActionButton.setVisibility(View.GONE);
        }
    }

    public void getPush() {
        threadPool.execute(() -> {
            push push = appApi.getPush();
            if (push == null) return;
            int grade = 0;
            if (sno != null && sno.length() == 9) {
                grade = Integer.parseInt(sno.substring(4, 6));
            }
            if (push.getTouser() == 1)
                if (push.getSystem().equals("android") || push.getSystem().equals("all"))
                    if ("all".equals(push.getSomeone()) || push.getSomeone().contains(xh_text) || push.getGrade() == grade)
                        EventBus.getDefault().post(new MessageEvent("MainActivity", 3, push));
        });
    }

    public void update() {
        threadPool.execute(() -> {
            Version version = appApi.update("android");
            if (version == null) return;
            if (version.isUpdate()) {
                EventBus.getDefault().post(new MessageEvent("MainActivity", 2, version));
            }
        });
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1 && resultCode == Activity.RESULT_OK && data != null) {
            Uri selectedImage = data.getData();
            String[] filePathColumn = {MediaStore.Images.Media.DATA};
            assert selectedImage != null;
            Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
            assert cursor != null;
            cursor.moveToFirst();
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            couplesBg = cursor.getString(columnIndex);
            cursor.close();
            if (couplesBg != null) {
                Bitmap bitmap = BitmapFactory.decodeFile(couplesBg);
                if (bitmap != null) {
                    Glide.with(this).load(couplesBg).into(course_img);
                }
            }
        }


        if (requestCode == AppSettingsDialog.DEFAULT_SETTINGS_REQ_CODE) {
            // Do something after user returned from app settings screen, like showing a Toast.
            setWallpaper();
        }

    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                           @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        // Forward results to EasyPermissions
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
    }


    @Override
    public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) {

    }

    @Override
    public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) {
        if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) {
            new AppSettingsDialog.Builder(this)
                    .setTitle("权限申请")
                    .setRationale("如果没有请求的权限，此应用可能无法正常工作。请打开应用设置以修改应用权限。")
                    .build().show();
        }

    }


    @SuppressLint("SetTextI18n")
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(MessageEvent event) {
        if (event.getEvent().equals("MainActivity"))
            switch (event.getWhat()) {
                case 1:
                    daka.setText(event.getMessage());
                    break;
                case 2:
                    Version version = (Version) event.getObj();
                    UpdateDialog updateDialog = new UpdateDialog.Builder(MainActivity.this)
                            .setNewVersion(version.getVersionName())
                            .setOldVersion(version.getOldVersionName())
                            .setInfo(version.getInfo())
                            .setDate(version.getDate())
                            .goMarket(v -> market.startMarket(MainActivity.this))
                            .goKuan(v -> {
                                Uri uri = Uri.parse("https://www.coolapk.com/apk/246419");
                                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                                startActivity(intent);
                            })
                            .create();
                    updateDialog.show();
                    UiUtils.setDialogWindowAttr(updateDialog, MainActivity.this);
                    break;

                case 3:
                    int push_id = SharedPreferencesUtil.getIntSp(MainActivity.this, "push_id", 0);
                    push push = (push) event.getObj();
                    if (push_id != push.getId()) {
                        final AlertDialog alertDialog = new AlertDialog(MainActivity.this);
                        alertDialog.builder();
                        alertDialog.setGone()
                                .setTitle(push.getTitle())
                                .setMsg(push.getNotice())
                                .setCancelable(false)
                                .setImg(push.getImg())
                                .setMsgGravity(false)
                                .setNegativeButton("朕已阅", R.color.colorAccent, v -> {
                                    SharedPreferencesUtil.putIntSp(MainActivity.this, "push_id", push.getId());
                                    alertDialog.dismiss();
                                    if (NetCheckUtil.checkNet(MainActivity.this)) {
                                        appApi.readPush(push.getId() + "");
                                    }
                                }).show();
                    }
                    int pushDisShow = SharedPreferencesUtil.getIntSp(this, "pushDisShow", -1);
                    if (pushDisShow != push_id) {
                        cardView.setVisibility(View.VISIBLE);
                        title.setText(push.getTitle());
                        msg.setText(push.getNotice());
                    }
                    break;
                case 4:
                    kao();
                    break;
                case 5:
                    initAvatarName();
                    break;
                case 6:
                    coupleSchedule();
                    break;
                case 7:
                    setWallpaper();
                    break;
                case 8:
                    viewPagerView();
                    break;
                case 9:
                    setWallpaper();
                    coupleSchedule();
                    initAvatarName();
                    viewPagerView();
                    kao();
                    break;
                case 10:
                    TimeTools.course_zhoushu(MainActivity.this);
                    intiWeekValue();
                    break;
                case 11:
                    eb.setText(event.getMessage());
                    if (!StringUtil.isEmpty(event.getTitle()))
                        eb_title.setText(event.getTitle());
                    break;
                case 12:
                    daka.setText(event.getZhou() + "次");
                    daka_title.setText(event.getMessage());
                    break;
                case 13:
                    ip.setText(event.getMessage());
                    break;
                case 14:
                    consummer.setText(event.getMessage());
                    if (!StringUtil.isEmpty(event.getTitle()))
                        consummer_title.setText(event.getTitle());
                    break;
                case 15:
                    book.setText(event.getMessage());
                    if (!StringUtil.isEmpty(event.getTitle()))
                        book_title.setText(event.getTitle());
                    break;
                case 16:
                    BookBorrow bookBorrow = (BookBorrow) event.getObj();
                    if (bookBorrow != null) {
                        if (bookBorrow.getExpiredNumber() > 0) {
                            book.setText(bookBorrow.getExpiredNumber() + "本");
                            book.setTextColor(getColor(R.color.mb_red));
                            book_title.setText("超期图书");
                            SharedPreferencesUtil.putStringSp(this, "bookNum", bookBorrow.getExpiredNumber() + "本");
                            SharedPreferencesUtil.putStringSp(this, "bookStatus", "超期图书");
                        } else if (bookBorrow.getExtendedNumber() > 0) {
                            book.setText(bookBorrow.getExtendedNumber() + "本");
                            book.setTextColor(getColor(R.color.yellow));
                            book_title.setText("即将到期");
                            SharedPreferencesUtil.putStringSp(this, "bookNum", bookBorrow.getExtendedNumber() + "本");
                            SharedPreferencesUtil.putStringSp(this, "bookStatus", "即将到期");
                        } else {
                            book.setText(bookBorrow.getBorrowBooksNumber() + "本");
                            book_title.setText("历史借阅图书");
                            SharedPreferencesUtil.putStringSp(this, "bookNum", bookBorrow.getBorrowBooksNumber() + "本");
                            SharedPreferencesUtil.putStringSp(this, "bookStatus", "历史借阅图书");
                        }

                    }
                    break;
                case 17:
                    book.setText(event.getMessage());
                    break;
                case 18:
                    if (consumerList != null && consumerList.size() > 0) {
                        consumerList = StringUtil.removeDuplicateConsumer(consumerList);
                        DialogView.moreConsumer(this, "校园卡消费", consumerList);
                    }
                    break;
                case 19:
                    if (borrowList != null && borrowList.size() > 0) {
                        borrowList = StringUtil.removeDuplicateBorrow(borrowList);
                        DialogView.moreBook(this, "图书借阅", borrowList);
                    }
                    break;
                case 20:
                    daka.setText(event.getMessage());
                    break;
            }
    }


}
